package code.structure.module.scene.manager
{
	import code.main.AppData;
	import code.structure.manager.background.BackGroundManager;
	import code.structure.module.configs.ConfigModel;
	import code.structure.module.configs.data.AreaConfigData;
	import code.structure.module.configs.data.ItemConfigData;
	import code.structure.module.scene.SceneController;
	import code.structure.module.scene.model.SceneModel;
	import code.structure.module.scene.model.data.SceneItemData;
	import code.structure.module.scene.view.YIsoWorld;
	import code.structure.module.scene.view.bg.BackGroundItemInfo;
	import code.structure.module.scene.view.iso.DoorIsoObject;
	import code.structure.module.scene.view.iso.RoadIsoObject;
	import code.structure.module.scene.view.iso.WallIsoObject;
	import code.structure.module.scene.view.iso.WallMuralIsoObject;
	import code.structure.module.scene.view.iso.YIsoObject;
	import code.structure.module.scene.view.iso.product.ProductPloughIsoObject;
	import code.structure.module.scene.view.iso.product.base.ProductIsoObject;
	import code.tools.method.ArrayUtil;
	import code.tools.method.CommonMethod;
	import code.tools.method.DictionaryUtil;
	import code.untils.CommandNameConst;
	import code.untils.ItemTypeConst;
	import code.untils.ProductStatusConst;
	import code.untils.SceneConfig;
	import code.untils.SwitchConfig;
	
	import com.patience.map.isometric.area.AreaMap;
	import com.patience.map.isometric.area.AreaMaskItem;
	import com.patience.map.isometric.core.IObject;
	import com.patience.map.isometric.utils.IsoUtils;
	import com.patience.mvc.context.Command;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Vector3D;
	import flash.utils.Dictionary;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;

	/**
	 *场景对象信息管理器 
	 * @author Yuri
	 * 
	 */
	public class InfoSceneManager
	{
		private var _isoWorld:YIsoWorld;
		private var _controller:SceneController;
		private var _sceneModel:SceneModel;
		private var _configModel:ConfigModel;
		private var _command:Command;
		/**
		 *生产性质的isoobject字典 
		 */
		private var _productIsoDic:Dictionary;
		/**
		 *耕地包含在上述种植字典中 
		 */
		private var _ploughIsoDic:Dictionary;
		
		/**
		 *墙上装饰物 
		 */
		private var _wallMuralIsoDic:Dictionary;
		
		/**
		 *门 
		 */
		private var _doorIsoDic:Dictionary;
		
		/**
		 *遮罩区域背景集合 
		 */
		private var _areaMaskBgDic:Dictionary;
		
		/**
		 *可以帮助好友家的物件字典（仅限于好友家） 
		 */
		private var _friendCanHelpIsoDic:Dictionary;
		
		
		private var _isoSubTypeDic:Dictionary;	
		
		private var _allIsoDic:Dictionary;
		//第一次进游戏里统计玩家场景里有多少个没解锁的物品
		private var _isFirst:Boolean = true;
		public function InfoSceneManager(iWorld:YIsoWorld = null)
		{
			_isoWorld = iWorld;
		}
		
		/**
		 *刷新场景数据 
		 * @param d
		 * 
		 */
		public function refreshWorldSceneData(dic:Dictionary):void{
			
			clearData();
			
			for each(var sceneData:SceneItemData in  dic ){
				var iso:YIsoObject = initIsoObject(sceneData,false);
				if(!iso) continue;
				isoWorld.addToWorld(iso);
				refreshSceneIsoCheck(iso);
			}
			updateUnLockArea(_sceneModel.unlockArea);
			if(_sceneModel.isMyScene){
			}else{
				refreshFriendSceneHelpInfo();
			}
			refreshWallMuralIsoAttachData();
			refreshDoorInfo();
			//第一次排序 完整排序 然后就是地板层取消
			isoWorld.isNeedObjectSort = true;
			isoWorld.isNeedFloorSort = true;
			isoWorld.sort();
			isoWorld.isNeedFloorSort = false;
		}
		
		/**
		 * 刷新场景对象的一个检测
		 * @param iso
		 * 
		 */
		private function refreshSceneIsoCheck(iso:YIsoObject):void{
		}
		
		/**
		 *更新解锁区域 
		 * 
		 */
		private function updateUnLockArea(unLockList:Array):void{
			_isoWorld.mapInfo.areaInfo.setHadUnLockedAreaKeyList(unLockList);
			for each(var mapArea:AreaMap in _isoWorld.mapInfo.areaInfo.areaMapDic){
				if(mapArea.unLocked){
					_isoWorld.mapGrid.addRangleGrids(mapArea.startX,mapArea.startZ,mapArea.areaXCount,mapArea.areaZCount);
				}else {
				/*	var isShopArea:Boolean = SwitchConfig.isSceneShop && SceneConfig.SHOP_AREA_INDEX.indexOf(mapArea.key)>-1 && AppData.isMyScene;
					if( isShopArea) _isoWorld.mapGrid.addRangleGrids(mapArea.startX,mapArea.startZ,mapArea.areaXCount,mapArea.areaZCount);*/
					addAreaMask(mapArea);
					refreshLockAreaSceneInfo(mapArea.key);
				}
			}
			_isFirst = false;
		}
		
		/**
		 * 更新一个区块的配置场景元素信息 
		 * @param areaKey 区块索引
		 * 
		 */
		private function refreshLockAreaSceneInfo(areaKey:String):void{
//			return;
		/*	var arr:Array = _configModel.analyStaticSceneInfo.getAreaStaticMapInfoByKey(areaKey);
			if(arr && arr.length>0){
				for each(var sceneData:SceneItemData in  arr ){
					var iso:YIsoObject = initIsoObject(sceneData,false);
					if(!iso) continue;
//					iso.isUnlock = false;
					isoWorld.addToWorld(iso);
					if(_isFirst) sceneData.data.lockNum += 1;
				}
			}*/
		}
		
		/**
		 * 场景操作解锁一个区块的场景 
		 * @param mapAreaData
		 * @param isOff 是否条件五折
		 * 
		 */
		public function unLockAreaScene(mapAreaData:AreaConfigData,isOff:Boolean = false):void{
			if(!mapAreaData) return;
			//调后台
			if(_sceneModel.unlockMapArea(mapAreaData,isOff)){
				_isoWorld.mapInfo.areaInfo.unlockAreaByKey(mapAreaData.id);
				var mapArea:AreaMap = _isoWorld.mapInfo.areaInfo.areaMapDic[mapAreaData.id] as AreaMap;
				
				_isoWorld.mapGrid.addRangleGrids(mapArea.startX,mapArea.startZ,mapArea.areaXCount,mapArea.areaZCount);
				if(mapArea && mapArea.maskBg){
					isoWorld.bgContainer.removeChild(mapArea.maskBg);
					mapArea.maskBg = null;
				}
			}
		}
		
		/**
		 *添加区域遮罩 
		 * @param mapArea
		 * 
		 */
		private function addAreaMask(mapArea:AreaMap):void{
			var fillColor:Number=0;
			var fillAlpha:Number=.7;
			mapArea.maskBg = new AreaMaskItem(mapArea.areaXCount*_isoWorld.size,mapArea.areaZCount*_isoWorld.size,fillColor,fillAlpha);
			isoWorld.bgContainer.addChild(mapArea.maskBg);
			var p:Vector3D = _isoWorld.getIsoWorldPoint3DByGridPosition(new Point(mapArea.startX,mapArea.startZ));
			var pp:Point = IsoUtils.isoToScreenXYZ(p.x,p.y,p.z);
			mapArea.maskBg.x = pp.x;
			mapArea.maskBg.y = pp.y;
			
			_areaMaskBgDic[mapArea.key] = mapArea.maskBg;
		}
		
		/**
		 *刷新随机物品 
		 * 
		 */
		private function refreshRandomItem():void{
			return;
		/*	if(_sceneModel.isMyScene){
				var count:int = _sceneModel.maxRefresh - _sceneModel.countRandom;
				if(count<=0) return;
				var randomList:Array = isoWorld.mapInfo.getFreeGridList();
				var pList:Array = ArrayUtil.randomCountList(randomList,count);
				var randomCount:int = pList.length;
				var shopDataList:Array = _sceneModel.calculateRefreshItemDataList(randomCount);
				var interval:uint = setInterval(createRefreshItem,1);
				function createRefreshItem():void{
					if(randomCount==0){
						clearInterval(interval);
						return;
					}
					var sceneData:SceneItemData = new SceneItemData();
					sceneData.data = shopDataList[randomCount-1] as ShopItemData;
					sceneData.systemCreat = true;
					var iso:YIsoObject = initIsoObject(sceneData);
					iso.position3D = isoWorld.getIsoWorldPoint3DByGridPosition(pList[randomCount-1] as Point);
					isoWorld.addToWorld(iso);
					_sceneModel.diyMapItem(iso,1);
					randomCount--;
				}
			}*/
		}
		
		/**
		 *刷新墙上装饰物绑定数据 
		 * 
		 */
		private function refreshWallMuralIsoAttachData():void{
			for each(var iso:WallMuralIsoObject in _wallMuralIsoDic){
				if(!iso.data.bindWall) continue;
				var count:int = iso.data.bindWall.length;
				var attachArr:Array = [];
				for(var i:int=0;i<count;i++){
					var wallIso:WallIsoObject = isoWorld.getIsoObjectById(iso.data.bindWall[i].toString()) as WallIsoObject;
					if(wallIso) attachArr.push(wallIso);
				}
				iso.attachedWallList = attachArr;
			}
		}
		
		/**
		 *刷新好友家场景帮助情况 
		 * 
		 */
		public function refreshFriendSceneHelpInfo():void{
		}
		
		/**
		 * 初始化一个完整的YisoObject
		 * @param d
		 * @return 
		 * 
		 */
		public function initIsoObject(d:SceneItemData,isUnlock:Boolean=true):YIsoObject{
			var yIso:YIsoObject = createIsoObject(d.data);
			if(!yIso) {
				trace("无法生成isoobject")
				return null;
			}
			yIso.parentWorld = isoWorld;
			if(d.position3D)
				yIso.position3D = d.position3D;
			yIso.id = d.id;
			yIso.size = isoWorld.size;
			yIso.data = d;
			yIso.isUnlock = isUnlock;
			return yIso;
		}
		
		/**
		 *创建场景实例 
		 * @param d
		 * @return 
		 * 
		 */
		private function createIsoObject(d:ItemConfigData):YIsoObject{
			var c:Class = SceneConfig.getIsoObjectClass(d);
			if(!c)return null;
			return (new c()) as YIsoObject;
		}
		
		public function addToWorld(iObject:IObject):void{
			if(iObject as ProductIsoObject){ 
				_productIsoDic[iObject] = iObject;
				if(iObject as ProductPloughIsoObject) _ploughIsoDic[iObject] = iObject;
			}
				
			else if(iObject as WallMuralIsoObject) _wallMuralIsoDic[iObject] = iObject;
			else if(iObject as DoorIsoObject) _doorIsoDic[iObject] = iObject;
			if(iObject as RoadIsoObject){
				_isoWorld.mapGrid.updateAnodeRangle(iObject.gridX,iObject.gridZ,iObject.floorXCount,iObject.floorZCount,1,SceneConfig.ROAD_WEIGHT);
			}
			_allIsoDic[iObject] = iObject;
			addisoSubTypeDic(iObject as YIsoObject);
		}
		
		public function removeFromWorld(iObject:IObject,isClear:Boolean = true):void{
			if(iObject as ProductIsoObject){
				delete _productIsoDic[iObject];
				if(iObject as ProductPloughIsoObject) delete _ploughIsoDic[iObject];
			}
			else if(iObject as WallMuralIsoObject) delete _wallMuralIsoDic[iObject];
			else if(iObject as DoorIsoObject && isClear) delete _doorIsoDic[iObject];
			if(iObject as RoadIsoObject){
				_isoWorld.mapGrid.updateAnodeRangle(iObject.gridX,iObject.gridZ,iObject.floorXCount,iObject.floorZCount);
			}
			removeisoSubTypeDic(iObject as YIsoObject);
		}
		
		/**
		 * 添加场景对象类型字典 
		 * @param iso
		 * 
		 */
		private function addisoSubTypeDic(iso:YIsoObject):void{
			if(!iso.data || !iso.data.data) return;
			var type:int = iso.data.data.subType;
			var id:int =iso.data.data.id;
			if(!_isoSubTypeDic) _isoSubTypeDic = new Dictionary();
			if(!_isoSubTypeDic[type]) _isoSubTypeDic[type] = new Dictionary();
			if(!_isoSubTypeDic[type][id]) _isoSubTypeDic[type][id] = [];
			if(_isoSubTypeDic[type][id].indexOf(iso)==-1)
				_isoSubTypeDic[type][id].push(iso);
		}
		
		/**
		 * 移除场景对象类型字典 
		 * @param iso
		 * 
		 */
		private function removeisoSubTypeDic(iso:YIsoObject):void{
			if(!iso.data || !iso.data.data) return;
			var type:int = iso.data.data.subType;
			var id:int = iso.data.data.id;
			if(!_isoSubTypeDic || !_isoSubTypeDic[type] || !_isoSubTypeDic[type][id] || _isoSubTypeDic[type][id].indexOf(iso) ==-1)  return;
			_isoSubTypeDic[type][id].splice( _isoSubTypeDic[type][id].indexOf(iso),1);
		}
		
		/**
		 *检测当对象发生数据变化时 
		 * @param iso
		 * @param oShopItemData
		 * 
		 */
		public function checkIsoObjectDataChange(iso:YIsoObject,oShopItemData:ItemConfigData):void{
			if(!iso.data.data) return;
			/*if(iso.data.data.subType != oShopItemData.subType
				|| iso.data.data.upgrade_series_id != oShopItemData.upgrade_series_id){
				removeisoSubTypeDic(iso);
				addisoSubTypeDic(iso);
			}*/
		}
		/**
		 *获取场景中特指物品Id的集合  
		 * @param subtype 类型 iMarketSubType
		 * @param itemid 具体id  可能是upgrade_series_id
		 * @param detailId 详细id 真实的itemid
		 * @param type 详细itype
		 * @param level 等级标准
		 * @param levelType 0：>= ,1:= ,2<
		 */
		public function getSceneIsoListByItemInfo(subtype:int,itemid:int=-1,detailId:int=-1,type:int=-1,level:int=0,levelType:int = 0):Array{
			if(!_isoSubTypeDic || subtype<=0) return null;
			if(!_isoSubTypeDic[subtype]) return null;
			
			var returnArr:Array;
			var isNeedLevel:Boolean = level>0;
			var i:int = 0;
			var count:int;
			var tempIso:YIsoObject;
			
			var isNeedType:Boolean = itemid<=0 && detailId<=0 && type>-1;
			
			if(itemid>0){
				if(_isoSubTypeDic[subtype][itemid]){
					returnArr =  _isoSubTypeDic[subtype][itemid].concat();
					if( !returnArr || returnArr.length==0) return null;
					
					var isNeedDetal:Boolean = detailId>0 && itemid!=detailId;
					if(isNeedDetal){
						isNeedLevel = false;
						count = returnArr.length;
						for(var j:int=count-1;j>-1;j--){
							tempIso = returnArr[j];
							if(tempIso.data.data.id != detailId) returnArr.splice(j,1);
						}
					}
				}
			}else{
				var arr:Array =  DictionaryUtil.getValues(_isoSubTypeDic[subtype] as Dictionary);
				var c:int = arr.length;
				for(i==0;i<c;i++){
					if(!returnArr) returnArr = arr[i];
					else
						returnArr = returnArr.concat(arr[i]);
				}
			}
			
			//只要满足其一都需要循环 isNeedLevel || isNeedType
			if(returnArr && returnArr.length>0 && (isNeedLevel || isNeedType)){
				count = returnArr.length;
				for(i=count-1;i>-1;i--){
					tempIso = returnArr[i];
					if(isNeedLevel) {
						if(levelType ==0 && tempIso.data.data.level<level){
							returnArr.splice(i,1);
							continue;
						}
						if(levelType ==1 && tempIso.data.data.level!=level){
							returnArr.splice(i,1);
							continue;
						}
						if(levelType ==2 && tempIso.data.data.level >= level){
							returnArr.splice(i,1);
							continue;
						}
					}
					if(isNeedType && tempIso.data.data.itemType != type) {
						returnArr.splice(i,1);
					}
				}
			}
			if(returnArr && returnArr.length==0) returnArr = null;
			return returnArr;
			
		}
		
		
		/**
		 *因场景状态的影响 
		 * 
		 */
		public function changeEffectByWorldStatus(status:String):void{
			refreshDoorInfo();
			for each(var iso:YIsoObject in allIsoDic){
				iso.refreshIsoWorldStatus(status);
			}
		}
		
		/**
		 * 
		 * 
		 */
		private function refreshDoorInfo():void
		{
			// TODO Auto Generated method stub
			for each(var door:DoorIsoObject in _doorIsoDic){
				door.showComponent(isoWorld.status == SceneConfig.SCENE_NORMAL);
			}
		}
		
		/**
		 *获取生产型场景元素通过id号 
		 * @param id
		 * @return 
		 * 
		 */
		public function getProductIsoById(id:String):ProductIsoObject{
			for each(var pIso:ProductIsoObject in _productIsoDic){
				if(pIso.id == id) return pIso;
			}
			return null;
		}
		
		/**
		 *通过场景id获取对象 
		 * @param id
		 * @return 
		 * 
		 */
		public function getIsoObjectById(id:String):YIsoObject{
			for each(var iso:YIsoObject in _allIsoDic){
				if(iso.id == id) return iso;
			}
			return null;
		}
		
		/**
		 *检测一个场景对象是否存在 
		 * @param iso
		 * @return 
		 * 
		 */
		public function checkIsoObjectIfExist(iso:IObject):Boolean{
			if(!iso || !isoWorld ||  !isoWorld.mapInfo) return false;
			return isoWorld.mapInfo.allIsoObjectList.indexOf(iso)!=-1;
		}
		/*********************************************************背景******************************************************/
		
		/**
		 *刷新背景层 (默认所有玩家的背景都是一样的) 
		 * 
		 */
		public function refreshBackGround():void{

			if(isoWorld.bgContainer && isoWorld.bgContainer.numChildren>0) return;
			var Xlength:Number = isoWorld.xNum*isoWorld.size;
			
			var countX:int =Xlength*2 /SceneConfig.BACKGROUND_GRID_WIDTH;
			var countY:int = Xlength /SceneConfig.BACKGROUND_GRID_HEIGHT;
			var key:String;
//			var sp:Sprite = new Sprite();
			for(var i:int=0;i<countX;i++){
				for(var j:int=0;j<countY;j++){
					key = i+"_"+j;
					if(BackGroundManager.getInstance().bgDic[key]){
						var bgItem:BackGroundItemInfo = new BackGroundItemInfo(i,j);
						bgItem.loadMaterial(BackGroundManager.bgPath+BackGroundManager.getInstance().bgDic[key]);
						bgItem.addEventListener(BackGroundItemInfo.DATA_COMPLETE_EVENT,onBgLoadedComplete);
					}
				}
			}
			
			var bgShape:Bitmap = new Bitmap();
			bgShape.bitmapData = new BitmapData(Xlength*2,Xlength);
			var loadedCount:int;
			var sum:int = countX*countY;
			function onBgLoadedComplete(e:Event):void{
				loadedCount++;
				var bgItem:BackGroundItemInfo = e.target as  BackGroundItemInfo;
				bgShape.bitmapData.copyPixels(bgItem.bitmapData,bgItem.bitmapData.rect,
					new Point(bgItem.xIndex*SceneConfig.BACKGROUND_GRID_WIDTH,bgItem.yIndex*SceneConfig.BACKGROUND_GRID_HEIGHT));
				bgItem.removeEventListener(BackGroundItemInfo.DATA_COMPLETE_EVENT,onBgLoadedComplete);
			}
			
			isoWorld.bgContainer.addChild(bgShape);
			
			var maskShape:Shape = new Shape();
			maskShape.graphics.beginFill(0,.7);
			maskShape.graphics.moveTo(Xlength,0);
			maskShape.graphics.lineTo(Xlength*2,0);
			maskShape.graphics.lineTo(Xlength*2,Xlength);
			maskShape.graphics.lineTo(0,Xlength);
			maskShape.graphics.lineTo(0,0);
			maskShape.graphics.lineTo(Xlength,0);
			
			maskShape.graphics.lineTo(Xlength*2,Xlength/2);
			maskShape.graphics.lineTo(Xlength,Xlength);
			maskShape.graphics.lineTo(0,Xlength/2);
			maskShape.graphics.lineTo(Xlength,0);
			
			isoWorld.bgContainer.addChild(maskShape);
			bgShape.x = -Xlength;
			maskShape.x = -Xlength;
			
		}
		
		/**
		 * 检测NPC可以站立的点 
		 * @param gridX 
		 * @param gridZ
		 * @param isCrossUnlockArea 是否需要突破未解锁区域
		 * @return 
		 * 
		 */
		public function getCanStandPoint(gridX:int,gridZ:int,isCrossUnlockArea:Boolean=false):Point{
			
			var p:Point = new Point(gridX,gridZ);
			var unlock:Boolean = _isoWorld.mapInfo.areaInfo.checkAreaIsUnLocked(gridX,gridZ);
			if(!unlock && !isCrossUnlockArea) return p;
			
			var arr:Array=[];
			var maxCount:int=5;
			var i:int;
			var count:int;
			while(i<maxCount && count==0){
				arr = _isoWorld.mapInfo.getCanStandRangleList(gridX-i,gridZ-i,2*i+1,2*i+1,i);
				//剔除npc
				count = arr.length;
				i++;
			}
			if(arr && arr.length>0){
				var index:int = CommonMethod.getRandomIndexFromArray(arr);
				var noBarrier:Array = String(arr[index]).split("_");
				p.x = int(noBarrier[0]);
				p.y = int(noBarrier[1]);
			}
			return p;
		}
		
		/**
		 *检测是否有可以去种植的土地（初始化 并且未等待种植进行中） 
		 * @return 
		 * 
		 */
		public function checkIfHaveCanSeedPlough():Boolean{
			for each(var iso:ProductPloughIsoObject in _ploughIsoDic){
				if(iso.productStatus == ProductStatusConst.PRODUCT_INIT_STATUS ){
					return true;
				}
			}
			return false;
		}
		
		/**
		 *改变一个物件的世界位置 
		 * @param iso
		 * @param gridX
		 * @param gridZ
		 * 
		 */
		public function changeIsoPosition(iso:YIsoObject,gridX:int,gridZ:int):void{
			iso.isMoving = true;
			iso.position3D = new Vector3D(gridX*_isoWorld.size,0,gridZ*_isoWorld.size);
			iso.isMoving = false;
		}
		
		/**
		 *解锁的建筑物 要通知其他模块 
		 * 更改开关
		 * @param itemType
		 * 
		 */
		public function functionBuildingUnlock(itemType:int):void{
			/*if(!_controller) return;
			if(!_command)_command = new Command(CommandNameConst.COMMAND_FUNCTIONBUILDING_UNLOCK);
			switch(itemType){
				case ItemTypeConst.MYSTERYSHOP_BUILD:
					SwitchConfig.isEnableResearch = true;
					break;
				case ItemTypeConst.ABILITY_BUILD:
					SwitchConfig.isEnableAbility = true;
					break;
				case ItemTypeConst.PROCURE_BUILD:
					SwitchConfig.isEnableProcure = true;
					break;
					
			}
			_command.data = itemType;
			_controller.dispatch(_command);*/
		}
		
		/**
		 *清空数据 
		 * 
		 */
		private function clearData():void
		{
			// TODO Auto Generated method stub
			_allIsoDic = new Dictionary();
			_areaMaskBgDic = new Dictionary();
			_productIsoDic = new Dictionary();
			_wallMuralIsoDic = new Dictionary();
			_friendCanHelpIsoDic = new Dictionary();
			_doorIsoDic = new Dictionary();
			_ploughIsoDic = new Dictionary();
			_isoSubTypeDic = new Dictionary();
		}

		public function get isoWorld():YIsoWorld
		{
			return _isoWorld;
		}

		public function set isoWorld(value:YIsoWorld):void
		{
			_isoWorld = value;
		}

		public function set controller(value:SceneController):void
		{
			_controller = value;
			if (value){
				_sceneModel = _controller.sceneModel;
				_configModel = _controller.configModel;
			}
		}
		
		/**
		 *移除一个区域的遮罩 
		 * @param key
		 * 
		 */
		public function removeAreaMaskBgByKey(key:String):void{
			var aItem:AreaMaskItem = _areaMaskBgDic[key] as AreaMaskItem;
			if(aItem && _isoWorld.bgContainer && _isoWorld.bgContainer.contains(aItem)){
				_isoWorld.bgContainer.removeChild(aItem);
			}
			delete _areaMaskBgDic[key];
		}
		
		/**
		 *移除所有遮罩背景 
		 * 
		 */
		private function removeAllAreaMaskBg():void{
			if(!_isoWorld) return;
			for (var key:String in _areaMaskBgDic){
				removeAreaMaskBgByKey(key);
			}
		}
		
		/**
		 *清空 
		 * 
		 */
		public function clear():void{
			removeAllAreaMaskBg();
			clearData();
		}

		/**
		 *场景中通过iso本身类型区分的字典 （itemType）
		 */
		public function get isoSubTypeDic():Dictionary
		{
			return _isoSubTypeDic;
		}

		/**
		 *所有对象 
		 */
		public function get allIsoDic():Dictionary
		{
			return _allIsoDic;
		}


	}
}